#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

// 已知
int t;
int n, m, x, y;
vector<int>g[1010];
bool vis[1010];
void dfs(int u, vector<int>ans)
{
    if (u == y)
    {
        for (auto x : ans)cout << x << " ";
        cout << endl;
        return;
    }
    for (auto x : g[u])
    {
        if (!vis[x])
        {
            vis[x] = 1;
            ans.push_back(x);
            dfs(x, ans);
            ans.pop_back();
            // 不用回溯，找到的第一个一定是路径最短的
        }
    }
}

int main() {

    cin >> t;
    while (t--)
    {
        cin >> n >> m >> x >> y;
        for (int i = 0, u, v;i < m;i++)
        {
            cin >> u >> v;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        for (int i = 1;i <= n;i++) sort(g[i].begin(), g[i].end());
        vis[x] = 1;
        dfs(x, { x });
        fill(vis, vis + 1010, 0);
        fill(g, g + 1010, vector<int>());
    }
    return 0;
}